package com.compty.paint.manager;

import java.util.List;

import com.compty.core.hibernate.HibernateEntityDao;
import com.compty.paint.domain.BackgroundImage;
import com.compty.paint.domain.Painting;

/**
 * 摆设背景管理
 * @CreateTime:2011-7-12 下午04:45:34
 */
public class BackgroundImageManager extends HibernateEntityDao<BackgroundImage>{

	/**
	 *@Todo:查找与作品匹配的摆设背景
	 *@CreateTime:2011-11-25 上午10:53:14
	 * @param painting 作品
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BackgroundImage> findBackgroundImagesByPainting(Painting painting) {
		// TODO Auto-generated method stub
		Long sharpId = painting.getSharpInfo().getId();
		Float width = painting.getWidth();
		Float height = painting.getHight();
		if( width == null || height == null){
			return null;
		}
		
		String hql = "select b from BackgroundImage b where 1=1 ";
		
		if(sharpId == 1){
			if( height >= 15 && height < 50){
				hql += " and b.size_square = '1'";
			}
			else if(height>= 50 && height < 70 ){
				hql += " and b.size_square = '2'";
			}
			else if(height >= 70 && height < 90 ){
				hql += " and b.size_square = '3'";
			}
			else if(height >= 90 && height < 110 ){
				hql += " and b.size_square = '4'";
			}
			else if(height >= 110 && height < 130 ){
				hql += " and b.size_square = '5'";
			}
			else if(height >= 130 && height < 160 ){
				hql += " and b.size_square = '6'";
			}
			else if(height >= 160 && height <= 230 ){
				hql += " and b.size_square = '7'";
			}else{
				hql += " and b.size_square = 'null'";
			}
		}
		else if(sharpId == 2 ){//长方形(竖)
			if( height >= 15 && height < 50){
				hql += " and b.size_vertical = '1'";
			}
			else if(height>= 50 && height < 70 ){
				hql += " and b.size_vertical = '2'";
			}
			else if(height >= 70 && height < 90 ){
				hql += " and b.size_vertical = '3'";
			}
			else if(height >= 90 && height < 110 ){
				hql += " and b.size_vertical = '4'";
			}
			else if(height >= 110 && height < 130 ){
				hql += " and b.size_vertical = '5'";
			}
			else if(height >= 130 && height < 160 ){
				hql += " and b.size_vertical = '6'";
			}
			else if(height >= 160 && height <= 230 ){
				hql += " and b.size_vertical = '7'";
			}else{
				hql += " and b.size_vertical = 'null'";
			}
		}
		else if( sharpId == 3  ){//长方形(横)
			if(width >= 20 && width < 40){
				hql += " and b.size_horizontal = '1'";
			}
			else if(width >= 40 && width < 80){
				hql += " and b.size_horizontal = '2'";
			}
			else if(width >= 80 && width < 120){
				hql += " and b.size_horizontal = '3'";
			}
			else if(width >= 120 && width < 150){
				hql += " and b.size_horizontal = '4'";
			}
			else if(width >= 150 && width < 180){
				hql += " and b.size_horizontal = '5'";
			}
			else if(width >= 180 && width <= 220){
				hql += " and b.size_horizontal = '6'";
			}else{
				hql += " and b.size_horizontal = 'null'";
			}
		}
		
		return super.find(hql);
	}

}
